package com.icinfo.cloud.provider.punish.api.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.common.utils.DesensitizeUtil;
import com.icinfo.cloud.provider.punish.actscode.mapper.CaseActsCodeInfoMapper;
import com.icinfo.cloud.provider.punish.actscode.mapper.CaseActsCodeScreenStatisticsMapper;
import com.icinfo.cloud.provider.punish.actscode.model.CaseActsCodeInfo;
import com.icinfo.cloud.provider.punish.actscode.model.CaseActsCodeScreenStatistics;
import com.icinfo.cloud.provider.punish.api.dto.CaseActsCodeBigScreenQueryDto;
import com.icinfo.cloud.provider.punish.api.service.ICaseActsCodeService;
import com.icinfo.cloud.provider.punish.api.vo.*;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceRegisterMainInfoMapper;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourceRegisterMainInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CasePartiesRecordQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainDetailSimpleInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICasePartiesRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseReasonMainRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartiesInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartiesRecordVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseReasonMainRecordVo;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 行为码查询案件详情service
 *
 * @Author mahan
 * @Date 2022/11/10
 */
@Slf4j
@Service
public class CaseActsCodeServiceImpl extends MyBatisServiceSupport implements ICaseActsCodeService {

	@Autowired
	private CaseActsCodeInfoMapper caseActsCodeInfoMapper;
	@Resource
	private CaseMainInfoMapper caseMainInfoMapper;
	@Resource
	private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
	@Resource
	private CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;
	@Resource
	private CasePartiesRecordMapper casePartiesRecordMapper;
	@Resource
	private CaseDocumentRecordMapper caseDocumentRecordMapper;
	@Resource
	private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
	@Resource
	private CaseMainDetailInfoMapper caseMainDetailInfoMapper;
	@Resource
	private CaseActsCodeScreenStatisticsMapper caseActsCodeScreenStatisticsMapper;
	@Resource
	private ICaseMainDetailSimpleInfoService caseMainDetailSimpleInfoService;
	@Resource
	private ICasePartiesRecordService casePartiesRecordService;
	@Resource
	private ICaseReasonMainRecordService caseReasonMainRecordService;
	@Resource
	private CaseSourceRegisterMainInfoMapper caseSourceRegisterMainInfoMapper;

	/**
	 * 案件详情-行政处罚
	 *
	 * @param caseActsCode
	 * @return
	 */
	@Override
	public CaseActsCodeInfoVo getCaseActsCodeInfo(String caseActsCode) {
		CaseActsCodeInfoVo reVo = new CaseActsCodeInfoVo();
		CaseActsCodeInfo codeInfoParam = new CaseActsCodeInfo();
		codeInfoParam.setCaseActsCode(caseActsCode);
		CaseActsCodeInfo caseActsCodeInfo = caseActsCodeInfoMapper.selectOne(codeInfoParam);
		if (caseActsCodeInfo == null) {
			throw new BusinessException("未查询到指定的行政行为码");
		}
		BeanUtil.copyProperties(caseActsCodeInfo, reVo);
		reVo.setQrCodeUrl(this.getImageBase64(reVo.getQrCodeUrl()));
		reVo.setBarCodeUrl(this.getImageBase64(reVo.getBarCodeUrl()));
		//获取案件阶段、处罚事项
		CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseActsCodeInfo.getCaseId());
		if (caseMainInfo != null) {
			reVo.setCaseCurrentStageName(caseMainInfo.getCaseCurrentStageName());
			reVo.setCaseCurrentLinkName(caseMainInfo.getCaseCurrentLinkName());
			//获取案由
			reVo.setCaseReasons(this.getCaseReasons(caseMainInfo.getId()));
		}
		return reVo;
	}

	/**
	 * 案件详情-案件基本信息、处罚结果、当事人信息
	 *
	 * @param caseActsCode
	 * @return
	 */
	@Override
	public CaseActsCodeDetailInfoVo getCaseActsCodeDetailInfo(String caseActsCode) {
		CaseActsCodeDetailInfoVo reVo = new CaseActsCodeDetailInfoVo();
		//获取基本信息
		CaseMainInfo queryParam = new CaseMainInfo();
		queryParam.setCaseActsCode(caseActsCode);
		CaseMainInfo caseMainInfo = caseMainInfoMapper.selectOne(queryParam);
		if (caseMainInfo == null) {
			throw new BusinessException("未查询到案件信息");
		}
		Map<String, String> fieldMapping = new HashMap<>();
		fieldMapping.put("caseDeptCode","deptCode");
		fieldMapping.put("caseOrgCode","orgCode");
		CopyOptions copyOptions = CopyOptions.create().setFieldMapping(fieldMapping);
		BeanUtil.copyProperties(caseMainInfo, reVo,copyOptions);
		reVo.setCaseTypeText(CaseTypeEnum.getValueByCode(caseMainInfo.getCaseType()));
		reVo.setCaseRegisterTime(caseMainInfo.getCaseRegistTime());
		//获取执法人员信息
		this.getHandlePerson(reVo, caseMainInfo.getId());

		//获取当事人信息
		reVo.setPartyInfoList(this.getPartyInfoList(caseMainInfo.getId()));

		//获取处罚结果：只展示审批通过的决定书
		List<CaseActsCodePunishInfoVo> punishInfoVoList = caseDocumentRecordMapper.selectPunishDocumentAuditPassList(caseMainInfo.getId());
		if (punishInfoVoList == null || punishInfoVoList.isEmpty()) {
			reVo.setPunishInfoList(null);
		} else {
			punishInfoVoList.forEach(e -> {
				this.getPublicityContentAndPunishKindsAndPunishMoney(caseMainInfo, e.getPartyId(), caseMainInfo.getHandleType(), e);
			});
			reVo.setPunishInfoList(punishInfoVoList);
		}
		return reVo;
	}

	/**
	 * 一码知全貌-行政处罚
	 *
	 * @param caseActsCode
	 * @return
	 */
	@Override
	public CaseActsCodeKnowPunishInfoVo getCaseActsCodePunishInfo(String caseActsCode) {
		CaseActsCodeKnowPunishInfoVo reVo = new CaseActsCodeKnowPunishInfoVo();
		//获取主表数据
		CaseMainInfo queryParam = new CaseMainInfo();
		queryParam.setCaseActsCode(caseActsCode);
		CaseMainInfo caseMainInfo = caseMainInfoMapper.selectOne(queryParam);
		CaseSourceRegisterMainInfo caseSourceRegisterMainInfo = caseSourceRegisterMainInfoMapper.selectByPrimaryKey(caseMainInfo.getId());
		if (caseMainInfo == null) {
			throw new BusinessException("未查询到案件信息");
		}
		reVo.setCaseId(caseMainInfo.getId());
		reVo.setCaseActsCode(caseActsCode);
		reVo.setCaseRegisterTime(caseMainInfo.getCaseRegistTime());
		reVo.setCaseCurrentStageName(caseMainInfo.getCaseCurrentStageName());
		reVo.setCaseCurrentLinkName(caseMainInfo.getCaseCurrentLinkName());
		reVo.setCaseOrgName(caseMainInfo.getCaseOrgName());
		reVo.setCaseCreateTime(caseMainInfo.getCaseCreateTime());
		if (null != caseSourceRegisterMainInfo) {
			reVo.setCaseCreateTime(DateUtil.dateToLocalDateTime(caseSourceRegisterMainInfo.getRegisterTime()));
		}
		//获取案件二维码
		CaseActsCodeInfo codeInfoParam = new CaseActsCodeInfo();
		codeInfoParam.setCaseActsCode(caseActsCode);
		CaseActsCodeInfo caseActsCodeInfo = caseActsCodeInfoMapper.selectOne(codeInfoParam);
		if (caseActsCodeInfo != null) {
			//图片转base64
			reVo.setQrCodeUrl(caseActsCodeInfo.getQrCodeUrl());
			reVo.setQrCodeImageData(this.getImageBase64(caseActsCodeInfo.getQrCodeUrl()));
		}
		//获取案由
		reVo.setCaseReasons(this.getCaseReasons(caseMainInfo.getId()));
		//获取阶段信息
		List<CaseActsCodeStageVo> caseStageList = new ArrayList<>();
		CaseActsCodeStageVo caseCreate = new CaseActsCodeStageVo();
		if (null != caseSourceRegisterMainInfo) {
			caseCreate.setStageName("案源登记");
			caseCreate.setStageTime(DateUtil.dateToLocalDateTime(caseSourceRegisterMainInfo.getRegisterTime()));
		} else {
			caseCreate.setStageName("案件登记");
			caseCreate.setStageTime(caseMainInfo.getCaseCreateTime());
		}
		caseStageList.add(caseCreate);
		CaseActsCodeStageVo caseRegister = new CaseActsCodeStageVo();
		caseRegister.setStageName("案件立案");
		caseRegister.setStageTime(caseMainInfo.getCaseRegistTime());
		caseStageList.add(caseRegister);
		CaseActsCodeStageVo caseEnd = new CaseActsCodeStageVo();
		caseEnd.setStageName("案件办结");
		caseEnd.setStageTime(caseMainInfo.getCaseEndTime());
		caseStageList.add(caseEnd);
		reVo.setCaseStageList(caseStageList);
		return reVo;
	}

	/**
	 * 大屏统计-行政检查-行政处罚
	 *
	 * @return
	 */
	@Override
	public CaseActsCodeBigScreenStatisticsVo getBigScreenStatistics() {
		CaseActsCodeBigScreenStatisticsVo reVo = new CaseActsCodeBigScreenStatisticsVo();
		//行政检查-处罚办案中：案件码不为空，检查码不为空，并且检查码开头两位是02，并且是办案中
		Example casePunishingExample = new Example(CaseMainInfo.class);
		casePunishingExample.createCriteria().andEqualTo("caseStatus", CaseStatusEnum.HANDLING_CASE.getCode())
				.andIsNotNull("caseExternalActsCode").andIsNotNull("caseActsCode")
				.andCondition("substr(case_external_acts_code,1,2) = '02'");
		int casePunishingNum = caseMainInfoMapper.selectCountByExample(casePunishingExample);
		reVo.setCasePunishingNum(casePunishingNum);

		//行政检查-处罚已结案：案件码不为空，检查码不为空，并且检查码开头两位是02，并且是已结案
		Example caseEndNumExample = new Example(CaseMainInfo.class);
		caseEndNumExample.createCriteria().andEqualTo("caseStatus", CaseStatusEnum.END_CASE.getCode())
				.andIsNotNull("caseExternalActsCode").andIsNotNull("caseActsCode")
				.andCondition("substr(case_external_acts_code,1,2) = '02'");
		int caseEndNum = caseMainInfoMapper.selectCountByExample(caseEndNumExample);
		reVo.setCaseEndNum(caseEndNum);

		//行政检查-转处罚：检查码、处罚码不为空，并且检查码已02开头
		Example transferPunishNumExample = new Example(CaseMainInfo.class);
		transferPunishNumExample.createCriteria().andIsNotNull("caseExternalActsCode").andIsNotNull("caseActsCode")
				.andCondition("substr(case_external_acts_code,1,2) = '02'");
		int transferPunishNum = caseMainInfoMapper.selectCountByExample(transferPunishNumExample);
		reVo.setTransferPunishNum(transferPunishNum);

		//行政处罚-赋码数
		Example assignCodeNumExample = new Example(CaseMainInfo.class);
		assignCodeNumExample.createCriteria().andIsNotNull("caseActsCode");
		int assignCodeNum = caseMainInfoMapper.selectCountByExample(assignCodeNumExample);
		reVo.setAssignCodeNum(assignCodeNum);

		List<CaseActsCodeScreenStatistics> list = caseActsCodeScreenStatisticsMapper.selectAll();
		CaseActsCodeScreenStatistics screenStatistics = list.get(0);
		//行政处罚-转强制
		reVo.setCaseTransferForceNum(screenStatistics.getCaseTransferForceNum());
		//行政处罚-强制执行中
		reVo.setCaseForceHandlingNum(screenStatistics.getCaseForceHandlingNum());
		//行政处罚-执行已完成
		reVo.setCaseExecuteFinishNum(screenStatistics.getCaseExecuteFinishNum());
		reVo.setForceCodeNum(screenStatistics.getForceCodeNum());
		reVo.setTransferReconsiderNum(screenStatistics.getTransferReconsiderNum());
		reVo.setReconsiderAcceptNum(screenStatistics.getReconsiderAcceptNum());
		reVo.setReconsiderCompleteNum(screenStatistics.getReconsiderCompleteNum());
		reVo.setReconsiderCodeNum(screenStatistics.getReconsiderCodeNum());
		return reVo;
	}

	/**
	 * 大屏-行政处罚分页列表查询
	 *
	 * @return
	 */
	@Override
	public List<CaseActsCodeBigScreenListVo> queryCaseActsCodeBigScreenPage(CaseActsCodeBigScreenQueryDto dto) {
		PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
		List<CaseActsCodeBigScreenListVo> reList = caseMainInfoMapper.queryCaseActsCodeBigScreenPage(dto.getCaseActsCode(), dto.getIsConnect());
		if (reList != null && !reList.isEmpty()) {
			for (CaseActsCodeBigScreenListVo vo : reList) {
				if (StrUtil.isEmpty(vo.getCaseExternalActsCode())) {
					vo.setCaseExternalActsCodeStatus("否");
				} else {
					vo.setCaseExternalActsCodeStatus("是");
				}
				vo.setCaseStatusText(CaseStatusEnum.getValueByCode(vo.getCaseStatus()));
				//获取案由
				vo.setCaseReasons(this.getCaseReasons(vo.getCaseId()));
				//获取当事人
				List<CaseActsCodePartyVo> partyVos = this.getPartyInfoList(vo.getCaseId());
				if (partyVos.size() == Constant.INTEGER_1) {
					CaseActsCodePartyVo partyVo = partyVos.get(Constant.INTEGER_0);
					vo.setPartyName(partyVo.getPartyName());
					vo.setPartyIdCard(partyVo.getPartyIdentityCode());
				} else {
					CaseActsCodePartyVo partyVo = partyVos.get(Constant.INTEGER_0);
					vo.setPartyName(partyVo.getPartyName() + "等" + partyVos.size() + "个");
					vo.setPartyIdCard(partyVo.getPartyIdentityCode() + "等" + partyVos.size() + "个");
				}
			}
		}
		return reList;
	}

	/**
	 * 根据oss图片地址，转为base64
	 *
	 * @param imageUrl
	 * @return
	 */
	private String getImageBase64(String imageUrl) {
		BufferedImage bufferedImage = null;
		try {
			bufferedImage = ImgUtil.read(new URL(imageUrl));
		} catch (MalformedURLException e) {
			log.warn("--------一码知全貌--转换案件二维码为Base64报错--------------", e);
		}
		String base64 = ImgUtil.toBase64(bufferedImage, ImgUtil.IMAGE_TYPE_PNG);
		return base64;
	}

	/**
	 * 获取处罚公示内容、处罚类型、罚款金额
	 *
	 * @param caseMainInfo
	 * @param partyId
	 * @param handleType
	 * @return
	 */
	private void getPublicityContentAndPunishKindsAndPunishMoney(CaseMainInfo caseMainInfo, String partyId, String handleType, CaseActsCodePunishInfoVo vo) {
		//简易程序
		if (Constant.STRING_1.equals(caseMainInfo.getCaseType())) {
			String publicText;
			CaseMainDetailSimpleInfo caseMainDetailSimpleInfo = caseMainDetailSimpleInfoService.getCaseMainDetailSimpleInfo(caseMainInfo.getId());
			CaseReasonMainRecordVo caseReasonMainRecord = caseReasonMainRecordService.getCaseReasonRecordByCaseId(caseMainInfo.getId());
			StringBuilder tmpTxt = new StringBuilder();
			List<CasePartiesRecordVo> casePartiesRecordVos = casePartiesRecordService.getCasePartiesInfo(caseMainInfo.getId());
			if (!ObjectUtils.isEmpty(casePartiesRecordVos)) {
				tmpTxt.append(casePartiesRecordVos.get(0).getPartyName());
			}
			tmpTxt.append("于");


			if (!ObjectUtils.isEmpty(caseMainDetailSimpleInfo.getCaseHappenTime())) {
				String time = caseMainDetailSimpleInfo.getCaseHappenTime().toLocalDate().toString();
				tmpTxt.append(time);
			} else {
				tmpTxt.append(" ");
			}
			tmpTxt.append("在");
			tmpTxt.append(caseMainDetailSimpleInfo.getCaseHappenAddressDetail());
			tmpTxt.append("实施了");
			tmpTxt.append(caseReasonMainRecord.getCaseReasonNameSimple());
			tmpTxt.append("的行为，违反了");
			tmpTxt.append(caseReasonMainRecord.getIllegalBasisFormat());
			tmpTxt.append("，依据");
			tmpTxt.append(caseReasonMainRecord.getPunishBasisFormat());
			tmpTxt.append(",作出如下行政处罚：");
			String punishDesc;
			//简易程序的展示处罚种类，若罚款的展示罚款金额。
			String punishKind = caseMainDetailSimpleInfo.getPunishKinds();
			if ("罚款".equals(punishKind)) {
				punishDesc = "罚款" + caseMainDetailSimpleInfo.getDraftPunishMoney() + "元";
			} else if (punishKind.contains("罚款") && punishKind.contains("警告")) {
				punishDesc = "警告并罚款" + caseMainDetailSimpleInfo.getDraftPunishMoney() + "元";
			} else {
				punishDesc = caseMainDetailSimpleInfo.getPunishKinds();
			}
			String casePunishContent = ObjectUtils.isEmpty(punishDesc) ? "-" : punishDesc;
			tmpTxt.append(casePunishContent);
			publicText = tmpTxt.toString();
			vo.setDecisionContent(publicText);
			vo.setPunishKinds(caseMainDetailSimpleInfo.getPunishKinds());
			vo.setDraftPunishMoney(caseMainDetailSimpleInfo.getDraftPunishMoney());
			vo.setPunishDecisionDate(caseMainInfo.getCaseCreateTime());
		} else {
			if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)) {
				CaseMainDetailAuxiliaryInfo param = new CaseMainDetailAuxiliaryInfo();
				param.setCaseId(caseMainInfo.getId());
				param.setPartyId(partyId);
				CaseMainDetailAuxiliaryInfo auxiliaryInfo = caseMainDetailAuxiliaryInfoMapper.selectOne(param);
				if (YesOrNoEnum.YES.getCode().equals(auxiliaryInfo.getIsPublicity())) {
					vo.setDecisionContent(auxiliaryInfo.getPublicityContent());
				} else {
					vo.setDecisionContent("不予公示");
				}
				vo.setPunishKinds(auxiliaryInfo.getPunishKinds());
				vo.setDraftPunishMoney(auxiliaryInfo.getDraftPunishMoney());
			} else {
				CaseMainDetailInfo param = new CaseMainDetailInfo();
				param.setCaseId(caseMainInfo.getId());
				CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectOne(param);
				if (YesOrNoEnum.YES.getCode().equals(caseMainDetailInfo.getIsPublicity())) {
					vo.setDecisionContent(caseMainDetailInfo.getPublicityContent());
				} else {
					vo.setDecisionContent("不予公示");
				}
				vo.setPunishKinds(caseMainDetailInfo.getPunishKinds());
				vo.setDraftPunishMoney(caseMainDetailInfo.getDraftPunishMoney());
			}
		}
	}

	/**
	 * 获取当事人信息
	 *
	 * @param caseId
	 */
	private List<CaseActsCodePartyVo> getPartyInfoList(String caseId) {
		List<CaseActsCodePartyVo> reList = new ArrayList<>();
		Example partyExample = new Example(CasePartiesRecord.class);
		partyExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", "1");
		partyExample.orderBy("partyType").desc();
		CasePartiesRecordQueryDto queryDto = new CasePartiesRecordQueryDto();
		queryDto.setCaseId(caseId);
		queryDto.setIsQueryInvalidData(YesOrNoEnum.NO.getCode());
		List<CasePartiesInfoVo> partiesRecords = casePartiesRecordMapper.selectCasePartiesInfoList(queryDto);
		partiesRecords.forEach(e -> {
			CaseActsCodePartyVo vo = new CaseActsCodePartyVo();
			vo.setPartyId(e.getPartyId());
			vo.setPartyType(e.getPartyType());
			if (PartyTypeEnum.PERSON.getCode().equals(e.getPartyType())) {
				vo.setPartyIdentityCode(DesensitizeUtil.hideIdCard(e.getPartyIdentityCode()));
				vo.setContactPhone(DesensitizeUtil.hidePhone(e.getContactPhone()));
			}else {
				vo.setPartyIdentityCode(e.getPartyIdentityCode());
				vo.setContactPhone(e.getContactPhone());
			}
			vo.setPartyName(e.getPartyName());
			vo.setAddressAreas(e.getAddressAreasStr());
			vo.setAddressDetail(e.getAddressDetail());
			reList.add(vo);
		});
		return reList;
	}

	/**
	 * 获取办案人员信息
	 *
	 * @param reVo
	 * @param caseId
	 */
	private void getHandlePerson(CaseActsCodeDetailInfoVo reVo, String caseId) {
		//获取办案人员信息
		Example handlePersonRecordExample = new Example(CaseHandlePersonRecord.class);
		handlePersonRecordExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
		List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(handlePersonRecordExample);
		List<String> uids = new ArrayList<>();
		handlePersonRecords.forEach(e -> {
			if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())) {
				reVo.setMainHandlePerson(e.getHandlePersonName());
				reVo.setMainHandlePersonLawEnforcementCert(e.getLawEnforcementCert());
				uids.add(e.getHandlePersonId());
			} else if (HandlePersonTypeEnum.ASSIST.getCode().equals(e.getHandlePersonType())) {
				reVo.setHelpHandlePerson(e.getHandlePersonName());
				reVo.setHelpHandlePersonLawEnforcementCert(e.getLawEnforcementCert());
				uids.add(e.getHandlePersonId());
			}
		});
		if (CollUtil.isNotEmpty(uids)){
			reVo.setAgentIds(String.join(",",uids));
		}
	}

	/**
	 * 获取案由
	 *
	 * @param caseId
	 * @return
	 */
	private String getCaseReasons(String caseId) {
		List<String> caseReasons = new ArrayList<>();
		Example reasonExample = new Example(CaseReasonMainRecord.class);
		reasonExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
		List<CaseReasonMainRecord> recordList = caseReasonMainRecordMapper.selectByExample(reasonExample);
		if (recordList == null || recordList.isEmpty()) {
			return null;
		}
		recordList.forEach(e -> {
			caseReasons.add(e.getCaseReasonName());
		});
		return CollUtil.join(caseReasons, ";");
	}

}